package cn.biplam.back.operator.systemManage.fileupdown;

import java.util.ArrayList;

import cn.biplam.back.sql.dml.Insert;
import cn.biplam.common.client.DataFilter;
import cn.biplam.common.client.OperatorResult;
import cn.biplam.common.interfaces.DataOperator;
import cn.biplam.common.opcode.SysManageCode.FileUploadOptCode;
import cn.biplam.common.struc.SysStruc.FileUpLoadStru;
import cn.biplam.common.wrapper.ErrorMessage;

/**
 * 上传文件信息操作类
 * 表结构：
 * 文件ID	File_ID			VARCHAR2(20)
 * 主题ID	FILE_THEME_ID	CHAR(1)
 * 文件名		FILE_NAME		VARCHAR2(100)
 * 文件路径	FILE_PATH		VARCHAR2(200)
 * 上传用户	UPLOAD_USER		VARCHAR2(20)
 * 上传日期	UPLOAD_DATE		VARCHAR2(10)
 * 上传时间	UPLOAD_TIME		VARCHAR2(20)
 * @author 	WangSong 2009-6-13 下午02:16:16
 * @version 1.0
 */
public class FileUploadOpt extends DataOperator{
	/** 表名称 */
	private static final String tName="FILE_UPLOAD";
	private final String sKeyName="FILE_ID";
	private final String sThemeId="A";
	
	/**
	 * 创建系统序列管理表数据操作类
	 * @throws ErrorMessage
	 */
	public FileUploadOpt() throws ErrorMessage{
		super(tName);
		super.mainKey=sKeyName;
	}

	@Override
	protected OperatorResult _exchange() throws ErrorMessage {
		ArrayList<String> sql=new ArrayList<String>();
		if(opId.equals(FileUploadOptCode.Query_ByID)){
			this.queryByID(sql, filter);
			return doing(sql, Operator_Type.Select);
		}else if(opId.equals(FileUploadOptCode.Insert_File)){
			this.insertFile(sql, filter);
			return doing(sql, Operator_Type.DML);
		}else{
			throw new ErrorMessage("Operator Exchange outport not found:"+ opId+" !");
		}
	}
	
	/**
	 * 查询文件信息
	 * 参数: FILE_THEME_ID
	 */
	public void queryByID(ArrayList<String> sql,DataFilter filter) throws ErrorMessage {
		StringBuilder sb=new StringBuilder();
		sb.append("select * from ");
		sb.append(this.tableName);
		sb.append(" where FILE_ID='");
		sb.append(filter.getValue("FILE_ID"));
		sb.append("'");
		sql.add(sb.toString());
	}
	
	/**
	 * 插入文件
	 */
	public void insertFile(ArrayList<String> sql,DataFilter filter) throws ErrorMessage {
		Insert insert=new Insert(this.tableName);
		insert.putStringFieldIgnoreNull(sKeyName,this.generatorRowID());
		insert.putStringFieldIgnoreNull("FILE_THEME_ID", sThemeId);
		insert.putStringFieldDenyNull(FileUpLoadStru.FILE_NAME, filter.getValue(FileUpLoadStru.FILE_NAME));	
		insert.putStringFieldDenyNull(FileUpLoadStru.FILE_PATH, filter.getValue(FileUpLoadStru.FILE_PATH));	
		insert.putStringFieldIgnoreNull(FileUpLoadStru.UPLOAD_USER, filter.getValue(FileUpLoadStru.UPLOAD_USER));	
		insert.putStringFieldIgnoreNull(FileUpLoadStru.UPLOAD_DATE, filter.getValue(FileUpLoadStru.UPLOAD_DATE));	
		insert.putStringFieldIgnoreNull(FileUpLoadStru.UPLOAD_TIME, filter.getValue(FileUpLoadStru.UPLOAD_TIME));
		sql.add(insert.getSimpleSql());
	}
}